package com.centriole.serviceLog;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@SpringBootApplication
@EnableEurekaClient
@RestController
@ComponentScan("com.centriole")
//部署war包
public class ServiceLogApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ServiceLogApplication.class);
    }

    @Autowired
    private DiscoveryClient discoveryClient;

    public static void main(String[] args) {
        SpringApplication.run(ServiceLogApplication.class, args);
    }


    @RequestMapping("/reg.json")
    public List<ServiceInstance> getRegistered() {
        List<ServiceInstance> instances = discoveryClient.getInstances("SERVICE-LOG");
        try {
            System.out.println(instances.get(0).getUri().toURL().getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }

        return instances;
    }

}
